home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / mac / DirectX SDK / DXSDK / samples / Multimedia / VBSamples / DirectPlay / Conferencer / frmNetwork.frm < prev    next >
Text File  |  2001-10-08  |  35KB  |  948 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
  3. Begin VB.Form frmNetwork 
  4.    BorderStyle     =   3  'Fixed Dialog
  5.    Caption         =   "vbConferencer"
  6.    ClientHeight    =   4605
  7.    ClientLeft      =   45
  8.    ClientTop       =   330
  9.    ClientWidth     =   3930
  10.    Icon            =   "frmNetwork.frx":0000
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   4605
  15.    ScaleWidth      =   3930
  16.    StartUpPosition =   3  'Windows Default
  17.    Begin VB.Timer tmrVoice 
  18.       Enabled         =   0   'False
  19.       Interval        =   10
  20.       Left            =   6435
  21.       Top             =   975
  22.    End
  23.    Begin VB.CheckBox chkVoice 
  24.       Caption         =   "Enable Voice Chat"
  25.       Height          =   255
  26.       Left            =   1140
  27.       TabIndex        =   9
  28.       Top             =   3660
  29.       Value           =   1  'Checked
  30.       Width           =   1635
  31.    End
  32.    Begin MSComDlg.CommonDialog cdlSend 
  33.       Left            =   6360
  34.       Top             =   3180
  35.       _ExtentX        =   847
  36.       _ExtentY        =   847
  37.       _Version        =   393216
  38.       DialogTitle     =   "Send File"
  39.       Filter          =   "Any File |*.*"
  40.       Flags           =   4
  41.       InitDir         =   "C:\"
  42.    End
  43.    Begin VB.Timer tmrJoin 
  44.       Enabled         =   0   'False
  45.       Interval        =   50
  46.       Left            =   6420
  47.       Top             =   540
  48.    End
  49.    Begin VB.Timer tmrUpdate 
  50.       Enabled         =   0   'False
  51.       Interval        =   10
  52.       Left            =   6420
  53.       Top             =   60
  54.    End
  55.    Begin VB.TextBox txtCall 
  56.       Height          =   285
  57.       Left            =   60
  58.       TabIndex        =   0
  59.       Top             =   300
  60.       Width           =   2535
  61.    End
  62.    Begin VB.ListBox lstUsers 
  63.       Height          =   2595
  64.       Left            =   60
  65.       TabIndex        =   3
  66.       Top             =   1020
  67.       Width           =   3795
  68.    End
  69.    Begin VB.CommandButton cmdHangup 
  70.       Height          =   495
  71.       Left            =   3240
  72.       MaskColor       =   &H00FF0000&
  73.       Picture         =   "frmNetwork.frx":030A
  74.       Style           =   1  'Graphical
  75.       TabIndex        =   2
  76.       ToolTipText     =   "Hang up"
  77.       Top             =   120
  78.       UseMaskColor    =   -1  'True
  79.       Width           =   495
  80.    End
  81.    Begin VB.CommandButton cmdCall 
  82.       Default         =   -1  'True
  83.       Height          =   495
  84.       Left            =   2700
  85.       MaskColor       =   &H000000FF&
  86.       Picture         =   "frmNetwork.frx":0A0C
  87.       Style           =   1  'Graphical
  88.       TabIndex        =   1
  89.       ToolTipText     =   "Call a friend"
  90.       Top             =   120
  91.       UseMaskColor    =   -1  'True
  92.       Width           =   495
  93.    End
  94.    Begin VB.CommandButton cmdWhiteBoard 
  95.       Height          =   495
  96.       Left            =   2325
  97.       MaskColor       =   &H000000FF&
  98.       Picture         =   "frmNetwork.frx":110E
  99.       Style           =   1  'Graphical
  100.       TabIndex        =   6
  101.       ToolTipText     =   "Use the whiteboard"
  102.       Top             =   4020
  103.       UseMaskColor    =   -1  'True
  104.       Width           =   495
  105.    End
  106.    Begin VB.CommandButton cmdChat 
  107.       Height          =   495
  108.       Left            =   1125
  109.       MaskColor       =   &H000000FF&
  110.       Picture         =   "frmNetwork.frx":1A18
  111.       Style           =   1  'Graphical
  112.       TabIndex        =   4
  113.       ToolTipText     =   "Chat with someone"
  114.       Top             =   4020
  115.       UseMaskColor    =   -1  'True
  116.       Width           =   495
  117.    End
  118.    Begin VB.CommandButton cmdSendFile 
  119.       Height          =   495
  120.       Left            =   1725
  121.       MaskColor       =   &H000000FF&
  122.       Picture         =   "frmNetwork.frx":2322
  123.       Style           =   1  'Graphical
  124.       TabIndex        =   5
  125.       ToolTipText     =   "Transfer files to someone"
  126.       Top             =   4020
  127.       UseMaskColor    =   -1  'True
  128.       Width           =   495
  129.    End
  130.    Begin VB.Label Label1 
  131.       BackStyle       =   0  'Transparent
  132.       Caption         =   "Enter a name or IP to call"
  133.       Height          =   195
  134.       Index           =   1
  135.       Left            =   60
  136.       TabIndex        =   8
  137.       Top             =   60
  138.       Width           =   2475
  139.    End
  140.    Begin VB.Label Label1 
  141.       BackStyle       =   0  'Transparent
  142.       Caption         =   "Users currently in this session"
  143.       Height          =   315
  144.       Index           =   0
  145.       Left            =   60
  146.       TabIndex        =   7
  147.       Top             =   780
  148.       Width           =   3735
  149.    End
  150.    Begin VB.Menu mnuPopup 
  151.       Caption         =   "PopUp"
  152.       Visible         =   0   'False
  153.       Begin VB.Menu mnuExit 
  154.          Caption         =   "E&xit"
  155.       End
  156.    End
  157. End
  158. Attribute VB_Name = "frmNetwork"
  159. Attribute VB_GlobalNameSpace = False
  160. Attribute VB_Creatable = False
  161. Attribute VB_PredeclaredId = True
  162. Attribute VB_Exposed = False
  163. Option Explicit
  164. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  165. '
  166. '  Copyright (C) 1999-2001 Microsoft Corporation.  All Rights Reserved.
  167. '
  168. '  File:       frmNetwork.frm
  169. '
  170. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  171. Implements DirectPlay8Event
  172. Implements DirectPlayVoiceEvent8
  173.  
  174. 'You can make bigger or smaller chunks here
  175. Private Const mlFileChunkSize As Long = 512
  176.  
  177. 'Variables for file transfers
  178. Private moReceivedFiles As New Collection
  179. Private moSendFiles As New Collection
  180. Private mlSendUnique As Long
  181. 'Misc private variables
  182. Private moCallBack As DirectPlay8Event
  183. Private mfExit As Boolean
  184. Private mfTerminate As Boolean
  185. Private mlVoiceError As Long
  186.  
  187. Private Sub chkVoice_Click()
  188.     If gfNoVoice Then Exit Sub 'Ignore this since voice chat isn't possible on this session
  189.     If chkVoice.Value = vbChecked Then
  190.         ConnectVoice Me
  191.     ElseIf chkVoice.Value = vbUnchecked Then
  192.         If Not (dvClient Is Nothing) Then dvClient.UnRegisterMessageHandler
  193.         If Not (dvClient Is Nothing) Then dvClient.Disconnect DVFLAGS_SYNC
  194.         Set dvClient = Nothing
  195.     End If
  196. End Sub
  197.  
  198. Private Sub cmdCall_Click()
  199.     If txtCall.Text = vbNullString Then
  200.         MsgBox "You must type the name or address of the person you wish to call before I can make the call.", vbOKOnly Or vbInformation, "No callee"
  201.         Exit Sub
  202.     End If
  203.     Connect Me, txtCall.Text
  204. End Sub
  205.  
  206. Private Sub cmdChat_Click()
  207.     If lstUsers.ListCount < 2 Then
  208.         MsgBox "You must have at least two people in the session before you can chat.", vbOKOnly Or vbInformation, "Not enough people"
  209.         Exit Sub
  210.     End If
  211.     If ChatWindow Is Nothing Then Set ChatWindow = New frmChat
  212.     ChatWindow.Show vbModeless
  213.     'Notify everyone
  214.     SendOpenChatWindowMessage
  215.     Set moCallBack = ChatWindow
  216. End Sub
  217.  
  218. Private Sub cmdHangup_Click()
  219.     'Cleanup and quit
  220.     mfExit = True
  221.     Unload Me
  222. End Sub
  223.  
  224. Private Sub cmdSendFile_Click()
  225.     Dim lMsg As Long, lOffset As Long
  226.     Dim oBuf() As Byte
  227.     
  228.     If lstUsers.ListIndex < 0 Then
  229.         MsgBox "You must select someone to send a file to before sending one.", vbOKOnly Or vbInformation, "No selection"
  230.         Exit Sub
  231.     End If
  232.     If lstUsers.ListIndex < 1 Then
  233.         MsgBox "You must select someone other than yourself to send a file to before sending one.", vbOKOnly Or vbInformation, "No selection"
  234.         Exit Sub
  235.     End If
  236.  
  237.     'Ok, we can send a file.. Let them pick one
  238.     cdlSend.FileName = vbNullString
  239.     On Error Resume Next
  240.     cdlSend.ShowOpen
  241.     If Err Or (cdlSend.FileName = vbNullString) Then Exit Sub 'They clicked cancel
  242.     cdlSend.InitDir = GetFolder(cdlSend.FileName)
  243.     'Otherwise start the file send
  244.     LockSendCollection
  245.     Dim f As frmProgress
  246.     Set f = New frmProgress
  247.     With f
  248.         .sFileName = cdlSend.FileName
  249.         .lDPlayID = lstUsers.ItemData(lstUsers.ListIndex)
  250.         mlSendUnique = mlSendUnique + 1
  251.         .FileUniqueID = mlSendUnique
  252.         'We need to send a 'Request' message first
  253.         lOffset = NewBuffer(oBuf)
  254.         lMsg = MsgSendFileRequest
  255.         AddDataToBuffer oBuf, lMsg, LenB(lMsg), lOffset
  256.         AddDataToBuffer oBuf, mlSendUnique, LenB(mlSendUnique), lOffset
  257.         AddStringToBuffer oBuf, StripFileName(cdlSend.FileName), lOffset
  258.         dpp.SendTo lstUsers.ItemData(lstUsers.ListIndex), oBuf, 0, DPNSEND_NOLOOPBACK Or DPNSEND_GUARANTEED
  259.     End With
  260.     moSendFiles.Add f
  261.     UnlockSendCollection
  262. End Sub
  263.  
  264. Private Sub cmdWhiteBoard_Click()
  265.     If lstUsers.ListCount < 2 Then
  266.         MsgBox "You must have at least two people in the session before you can use the whiteboard.", vbOKOnly Or vbInformation, "Not enough people"
  267.         Exit Sub
  268.     End If
  269.     If WhiteBoardWindow Is Nothing Then Set WhiteBoardWindow = New frmWhiteBoard
  270.     WhiteBoardWindow.Show vbModeless
  271.     'Notify everyone
  272.     SendOpenWhiteBoardWindowMessage
  273.     Set moCallBack = WhiteBoardWindow
  274. End Sub
  275.  
  276. Private Sub Form_Load()
  277.     'First start our server.  We need to be running a server in case
  278.     'someone tries to connect to us.
  279.     
  280.     StartHosting Me
  281.     'Add ourselves to the listbox
  282.     lstUsers.AddItem gsUserName
  283.     lstUsers.ItemData(0) = glMyPlayerID
  284.     
  285.     'Now put up our system tray icon
  286.     With sysIcon
  287.         .cbSize = LenB(sysIcon)
  288.         .hwnd = Me.hwnd
  289.         .uFlags = NIF_DOALL
  290.         .uCallbackMessage = WM_MOUSEMOVE
  291.         .hIcon = Me.Icon
  292.         .sTip = "vbConferencer" & vbNullChar
  293.     End With
  294.     Shell_NotifyIcon NIM_ADD, sysIcon
  295. End Sub
  296.  
  297. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  298.     Dim ShellMsg As Long
  299.     
  300.     ShellMsg = X / Screen.TwipsPerPixelX
  301.     Select Case ShellMsg
  302.     Case WM_LBUTTONDBLCLK
  303.         ShowMyForm
  304.     Case WM_RBUTTONUP
  305.         'Show the menu
  306.         'If gfStarted Then mnuStart.Enabled = False
  307.         PopupMenu mnuPopup, , , , mnuExit
  308.     End Select
  309. End Sub
  310.  
  311. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  312.     If Not mfExit Then
  313.         Cancel = 1
  314.         Me.Hide
  315.     End If
  316. End Sub
  317.  
  318. Private Sub Form_Unload(Cancel As Integer)
  319.     Dim f As Form
  320.     Dim lCount As Long
  321.     
  322.     Me.Hide
  323.     Shell_NotifyIcon NIM_DELETE, sysIcon
  324.     Cleanup
  325.     For lCount = 1 To moSendFiles.Count 'Clear the collection
  326.         moSendFiles.Remove 1
  327.     Next
  328.     Set moSendFiles = Nothing
  329.     For lCount = 1 To moReceivedFiles.Count 'Clear the collection
  330.         moReceivedFiles.Remove 1
  331.     Next
  332.     Set moReceivedFiles = Nothing
  333.     
  334.     For Each f In Forms
  335.         If Not (f Is Me) Then
  336.             Unload f
  337.             Set f = Nothing
  338.         End If
  339.     Next
  340.     DeleteCriticalSection goSendFile
  341.     DeleteCriticalSection goReceiveFile
  342.     End
  343. End Sub
  344.  
  345. Private Sub mnuExit_Click()
  346.     mfExit = True
  347.     Unload Me
  348. End Sub
  349.  
  350. Private Sub ShowMyForm()
  351.     Me.Visible = True
  352. End Sub
  353.  
  354. Private Sub tmrJoin_Timer()
  355.     tmrJoin.Enabled = False
  356.     MsgBox "The person you are trying to reach did not accept your call.", vbOKOnly Or vbInformation, "Didn't accept"
  357.     StartHosting Me
  358. End Sub
  359.  
  360. Public Sub UpdatePlayerList()
  361.     Dim lCount As Long, dpPeer As DPN_PLAYER_INFO
  362.     Dim lInner As Long, fFound As Boolean
  363.     Dim lTotal As Long
  364.     
  365.     lTotal = dpp.GetCountPlayersAndGroups(DPNENUM_PLAYERS)
  366.     If lTotal > 1 Then
  367.         cmdHangup.Enabled = True
  368.         cmdCall.Enabled = False
  369.     End If
  370.     For lCount = 1 To lTotal
  371.         dpPeer = dpp.GetPeerInfo(dpp.GetPlayerOrGroup(lCount))
  372.         If (dpPeer.lPlayerFlags And DPNPLAYER_LOCAL) = DPNPLAYER_LOCAL Then
  373.             'Don't add me
  374.         Else
  375.             fFound = False
  376.             'Make sure they're not already added
  377.             For lInner = 0 To lstUsers.ListCount - 1
  378.                 If lstUsers.ItemData(lInner) = dpp.GetPlayerOrGroup(lCount) Then fFound = True
  379.             Next
  380.             If Not fFound Then
  381.                 'Go ahead and add them
  382.                 lstUsers.AddItem dpPeer.Name
  383.                 lstUsers.ItemData(lstUsers.ListCount - 1) = dpp.GetPlayerOrGroup(lCount)
  384.             End If
  385.         End If
  386.     Next
  387. End Sub
  388.  
  389. Private Sub SendOpenWhiteBoardWindowMessage()
  390.     Dim lMsg As Long, lOffset As Long
  391.     Dim oBuf() As Byte
  392.     
  393.     'Now let's send a message asking the host to accept our call
  394.     lOffset = NewBuffer(oBuf)
  395.     lMsg = MsgShowWhiteBoard
  396.     AddDataToBuffer oBuf, lMsg, LenB(lMsg), lOffset
  397.     dpp.SendTo DPNID_ALL_PLAYERS_GROUP, oBuf, 0, DPNSEND_NOLOOPBACK
  398. End Sub
  399.  
  400. Private Sub SendOpenChatWindowMessage()
  401.     Dim lMsg As Long, lOffset As Long
  402.     Dim oBuf() As Byte
  403.     
  404.     'Now let's send a message asking the host to accept our call
  405.     lOffset = NewBuffer(oBuf)
  406.     lMsg = MsgShowChat
  407.     AddDataToBuffer oBuf, lMsg, LenB(lMsg), lOffset
  408.     dpp.SendTo DPNID_ALL_PLAYERS_GROUP, oBuf, 0, DPNSEND_NOLOOPBACK
  409. End Sub
  410.  
  411. Private Sub RemovePlayer(ByVal lPlayerID As Long)
  412.     Dim lCount As Long
  413.     'Remove anyone who has this player id
  414.     For lCount = 0 To lstUsers.ListCount - 1
  415.         If lstUsers.ItemData(lCount) = lPlayerID Then lstUsers.RemoveItem lCount
  416.     Next
  417.     If Not (ChatWindow Is Nothing) Then ChatWindow.LoadAllPlayers
  418.     'Let's see if there are any files being sent to this user
  419.     Dim f As frmProgress
  420.     LockSendCollection
  421.     For Each f In moSendFiles
  422.         If f.lDPlayID = lPlayerID Then
  423.             'Notify the user
  424.             MsgBox "Cancelled transfering file " & f.sFileName & " because the user quit."
  425.             'Yup, get rid of this file
  426.             EraseSendFile f.FileUniqueID
  427.         End If
  428.     Next
  429.     UnlockSendCollection
  430.     'Now look through the receive collection
  431.     LockReceiveCollection
  432.     For Each f In moReceivedFiles
  433.         If f.lDPlayID = lPlayerID Then
  434.             'Notify the user
  435.             MsgBox "Cancelled receiving file " & f.sFileName & " because the user quit."
  436.             'Yup, get rid of this file
  437.             EraseReceiveFile f.FileUniqueID
  438.         End If
  439.     Next
  440.     UnlockReceiveCollection
  441.     If lstUsers.ListCount <= 1 Then 'We are the only person left
  442.         cmdCall.Enabled = True
  443.         cmdHangup.Enabled = False
  444.     End If
  445. End Sub
  446.  
  447. Private Function StripFileName(ByVal sFile As String) As String
  448.     'Get rid of the path to the file (Strip everything after the last \)
  449.     If InStr(sFile, "\") Then
  450.         StripFileName = Right$(sFile, Len(sFile) - InStrRev(sFile, "\"))
  451.     Else
  452.         StripFileName = sFile
  453.     End If
  454. End Function
  455.  
  456. Private Sub SendNextFilePart(ByVal lUniqueID As Long)
  457.     
  458.     Dim lNewMsg As Long, lNewOffSet As Long
  459.     Dim oBuf() As Byte, lChunkSize As Long
  460.     Dim oFile() As Byte, f As frmProgress
  461.     
  462.     'First we need to find the correct file in our send list
  463.     LockSendCollection
  464.     Set f = GetSendProgressForm(lUniqueID)
  465.     With f
  466.         'Send this chunk
  467.         lNewOffSet = NewBuffer(oBuf)
  468.         lNewMsg = MsgSendFilePart
  469.         AddDataToBuffer oBuf, lNewMsg, LenB(lNewMsg), lNewOffSet
  470.         AddDataToBuffer oBuf, .FileUniqueID, SIZE_LONG, lNewOffSet
  471.         'Is this chunk bigger than the amount we will send?
  472.         If .lCurrentPos + mlFileChunkSize > .lFileSize Then
  473.             'First send the chunksize
  474.             lChunkSize = .lFileSize - .lCurrentPos
  475.         Else
  476.             lChunkSize = mlFileChunkSize
  477.         End If
  478.         AddDataToBuffer oBuf, lChunkSize, LenB(lChunkSize), lNewOffSet
  479.         ReDim oFile(1 To lChunkSize)
  480.         'Now read in a chunk that size
  481.         If .filNumber = 0 Then
  482.             .filNumber = FreeFile
  483.             Open .sFileName For Binary Access Read As #.filNumber
  484.         End If
  485.         Get #.filNumber, , oFile
  486.         AddDataToBuffer oBuf, oFile(1), lChunkSize, lNewOffSet
  487.         dpp.SendTo .lDPlayID, oBuf, 0, DPNSEND_NOLOOPBACK Or DPNSEND_GUARANTEED
  488.         .lCurrentPos = .lCurrentPos + lChunkSize
  489.         'Update our transfer window
  490.         .SetValue .lCurrentPos
  491.         If .lCurrentPos >= .lFileSize Then
  492.             Close #.filNumber
  493.             'Now get rid of this member of the array
  494.             EraseSendFile .FileUniqueID
  495.         End If
  496.     End With
  497.     UnlockSendCollection
  498. End Sub
  499.  
  500. Public Sub EraseSendFile(ByVal lUnique As Long)
  501.     Dim lCount As Long, f As frmProgress
  502.     
  503.     'First we need to find the correct file in our send list
  504.     LockSendCollection
  505.     For lCount = moSendFiles.Count To 1 Step -1
  506.         Set f = moSendFiles.Item(lCount)
  507.         If f.FileUniqueID = lUnique Then
  508.             moSendFiles.Remove lCount
  509.             Unload f
  510.             Set f = Nothing
  511.             Exit For
  512.         End If
  513.     Next
  514.     UnlockSendCollection
  515. End Sub
  516. Public Sub EraseReceiveFile(ByVal lUnique As Long)
  517.     Dim lCount As Long, f As frmProgress
  518.     
  519.     'First we need to find the correct file in our send list
  520.     LockReceiveCollection
  521.     For lCount = moReceivedFiles.Count To 1 Step -1
  522.         Set f = moReceivedFiles.Item(lCount)
  523.         If f.FileUniqueID = lUnique Then
  524.             moReceivedFiles.Remove lCount
  525.             Unload f.RequestForm
  526.             Set f.RequestForm = Nothing
  527.             Unload f
  528.             Set f = Nothing
  529.             Exit For
  530.         End If
  531.     Next
  532.     UnlockReceiveCollection
  533. End Sub
  534.  
  535. Private Function GetSendProgressForm(ByVal lUnique As Long) As frmProgress
  536.     Dim f As frmProgress
  537.     
  538.     LockSendCollection
  539.     For Each f In moSendFiles
  540.         If f.FileUniqueID = lUnique Then
  541.             Set GetSendProgressForm = f
  542.             Exit For
  543.         End If
  544.     Next
  545.     UnlockSendCollection
  546. End Function
  547.  
  548. Private Function GetReceiveProgressForm(ByVal lUnique As Long) As frmProgress
  549.     Dim f As frmProgress
  550.     
  551.     LockReceiveCollection
  552.     For Each f In moReceivedFiles
  553.         If f.FileUniqueID = lUnique Then
  554.             Set GetReceiveProgressForm = f
  555.             Exit For
  556.         End If
  557.     Next
  558.     UnlockReceiveCollection
  559. End Function
  560.  
  561. Private Function GetFolder(ByVal sFile As String) As String
  562.     Dim lCount As Long
  563.     
  564.     For lCount = Len(sFile) To 1 Step -1
  565.         If Mid$(sFile, lCount, 1) = "\" Then
  566.             GetFolder = Left$(sFile, lCount)
  567.             Exit Function
  568.         End If
  569.     Next
  570.     GetFolder = vbNullString
  571. End Function
  572.  
  573. Private Sub tmrUpdate_Timer()
  574.     tmrUpdate.Enabled = False
  575.     If Not mfTerminate Then
  576.         MsgBox "The person you are trying to reach is not available.", vbOKOnly Or vbInformation, "Unavailable"
  577.     End If
  578.     StartHosting Me
  579.     mfTerminate = False
  580. End Sub
  581.  
  582. Private Sub tmrVoice_Timer()
  583.     tmrVoice.Enabled = False
  584.     MsgBox "Could not start DirectPlayVoice.  This sample will not have any voice capablities." & vbCrLf & "Error:" & CStr(mlVoiceError), vbOKOnly Or vbInformation, "No Voice"
  585.     gfNoVoice = True
  586.     chkVoice.Value = vbUnchecked
  587.     chkVoice.Enabled = False
  588. End Sub
  589.  
  590. 'We will hold a critical section for the two separate collections
  591. 'This will ensure that two threads can't access the data at the same time
  592. Public Sub LockSendCollection()
  593.     EnterCriticalSection goSendFile
  594. End Sub
  595.  
  596. Public Sub UnlockSendCollection()
  597.     LeaveCriticalSection goSendFile
  598. End Sub
  599.  
  600. Public Sub LockReceiveCollection()
  601.     EnterCriticalSection goReceiveFile
  602. End Sub
  603.  
  604. Public Sub UnlockReceiveCollection()
  605.     LeaveCriticalSection goReceiveFile
  606. End Sub
  607.  
  608. 'We will handle all of the msgs here, and report them all back to the callback sub
  609. 'in case the caller cares what's going on
  610. Private Sub DirectPlay8Event_AddRemovePlayerGroup(ByVal lMsgID As Long, ByVal lPlayerID As Long, ByVal lGroupID As Long, fRejectMsg As Boolean)
  611.     'VB requires that we must implement *every* member of this interface
  612.     If (Not moCallBack Is Nothing) Then moCallBack.AddRemovePlayerGroup lMsgID, lPlayerID, lGroupID, fRejectMsg
  613. End Sub
  614.  
  615. Private Sub DirectPlay8Event_AppDesc(fRejectMsg As Boolean)
  616.     'VB requires that we must implement *every* member of this interface
  617.     If (Not moCallBack Is Nothing) Then moCallBack.AppDesc fRejectMsg
  618. End Sub
  619.  
  620. Private Sub DirectPlay8Event_AsyncOpComplete(dpnotify As DxVBLibA.DPNMSG_ASYNC_OP_COMPLETE, fRejectMsg As Boolean)
  621.     'VB requires that we must implement *every* member of this interface
  622.     If (Not moCallBack Is Nothing) Then moCallBack.AsyncOpComplete dpnotify, fRejectMsg
  623. End Sub
  624.  
  625. Private Sub DirectPlay8Event_ConnectComplete(dpnotify As DxVBLibA.DPNMSG_CONNECT_COMPLETE, fRejectMsg As Boolean)
  626.     Dim lMsg As Long, lOffset As Long
  627.     Dim oBuf() As Byte
  628.     
  629.     If dpnotify.hResultCode = 0 Then 'Success!
  630.         cmdHangup.Enabled = True
  631.         'Now let's send a message asking the host to accept our call
  632.         lOffset = NewBuffer(oBuf)
  633.         lMsg = MsgAskToJoin
  634.         AddDataToBuffer oBuf, lMsg, LenB(lMsg), lOffset
  635.         dpp.SendTo DPNID_ALL_PLAYERS_GROUP, oBuf, 0, DPNSEND_NOLOOPBACK
  636.     Else
  637.         tmrUpdate.Enabled = True
  638.     End If
  639.     
  640.     'VB requires that we must implement *every* member of this interface
  641.     If (Not moCallBack Is Nothing) Then moCallBack.ConnectComplete dpnotify, fRejectMsg
  642. End Sub
  643.  
  644. Private Sub DirectPlay8Event_CreateGroup(ByVal lGroupID As Long, ByVal lOwnerID As Long, fRejectMsg As Boolean)
  645.     'VB requires that we must implement *every* member of this interface
  646.     If (Not moCallBack Is Nothing) Then moCallBack.CreateGroup lGroupID, lOwnerID, fRejectMsg
  647. End Sub
  648.  
  649. Private Sub DirectPlay8Event_CreatePlayer(ByVal lPlayerID As Long, fRejectMsg As Boolean)
  650.     Dim dpPeer As DPN_PLAYER_INFO
  651.     On Error Resume Next
  652.     dpPeer = dpp.GetPeerInfo(lPlayerID)
  653.     If (dpPeer.lPlayerFlags And DPNPLAYER_LOCAL) = DPNPLAYER_LOCAL Then
  654.         glMyPlayerID = lPlayerID
  655.         lstUsers.ItemData(0) = glMyPlayerID
  656.     End If
  657.     'VB requires that we must implement *every* member of this interface
  658.     If (Not moCallBack Is Nothing) Then moCallBack.CreatePlayer lPlayerID, fRejectMsg
  659. End Sub
  660.  
  661. Private Sub DirectPlay8Event_DestroyGroup(ByVal lGroupID As Long, ByVal lReason As Long, fRejectMsg As Boolean)
  662.     'VB requires that we must implement *every* member of this interface
  663.     If (Not moCallBack Is Nothing) Then moCallBack.DestroyGroup lGroupID, lReason, fRejectMsg
  664. End Sub
  665.  
  666. Private Sub DirectPlay8Event_DestroyPlayer(ByVal lPlayerID As Long, ByVal lReason As Long, fRejectMsg As Boolean)
  667.     Dim dpPeer As DPN_PLAYER_INFO
  668.     On Error Resume Next
  669.     If lPlayerID <> glMyPlayerID Then 'ignore removing myself
  670.         RemovePlayer lPlayerID
  671.     End If
  672.     If Not (ChatWindow Is Nothing) Then Set moCallBack = ChatWindow 'If the chat window is open, let them know about the departure.
  673.     'VB requires that we must implement *every* member of this interface
  674.     If (Not moCallBack Is Nothing) Then moCallBack.DestroyPlayer lPlayerID, lReason, fRejectMsg
  675.     
  676. End Sub
  677.  
  678. Private Sub DirectPlay8Event_EnumHostsQuery(dpnotify As DxVBLibA.DPNMSG_ENUM_HOSTS_QUERY, fRejectMsg As Boolean)
  679.     'VB requires that we must implement *every* member of this interface
  680.     If (Not moCallBack Is Nothing) Then moCallBack.EnumHostsQuery dpnotify, fRejectMsg
  681. End Sub
  682.  
  683. Private Sub DirectPlay8Event_EnumHostsResponse(dpnotify As DxVBLibA.DPNMSG_ENUM_HOSTS_RESPONSE, fRejectMsg As Boolean)
  684.     'VB requires that we must implement *every* member of this interface
  685.     If (Not moCallBack Is Nothing) Then moCallBack.EnumHostsResponse dpnotify, fRejectMsg
  686. End Sub
  687.  
  688. Private Sub DirectPlay8Event_HostMigrate(ByVal lNewHostID As Long, fRejectMsg As Boolean)
  689.     'VB requires that we must implement *every* member of this interface
  690.     If (Not moCallBack Is Nothing) Then moCallBack.HostMigrate lNewHostID, fRejectMsg
  691. End Sub
  692.  
  693. Private Sub DirectPlay8Event_IndicateConnect(dpnotify As DxVBLibA.DPNMSG_INDICATE_CONNECT, fRejectMsg As Boolean)
  694.     'VB requires that we must implement *every* member of this interface
  695.     If (Not moCallBack Is Nothing) Then moCallBack.IndicateConnect dpnotify, fRejectMsg
  696. End Sub
  697.  
  698. Private Sub DirectPlay8Event_IndicatedConnectAborted(fRejectMsg As Boolean)
  699.     'VB requires that we must implement *every* member of this interface
  700.     If (Not moCallBack Is Nothing) Then moCallBack.IndicatedConnectAborted fRejectMsg
  701. End Sub
  702.  
  703. Private Sub DirectPlay8Event_InfoNotify(ByVal lMsgID As Long, ByVal lNotifyID As Long, fRejectMsg As Boolean)
  704.     'VB requires that we must implement *every* member of this interface
  705.     If (Not moCallBack Is Nothing) Then moCallBack.InfoNotify lMsgID, lNotifyID, fRejectMsg
  706. End Sub
  707.  
  708. Private Sub DirectPlay8Event_Receive(dpnotify As DxVBLibA.DPNMSG_RECEIVE, fRejectMsg As Boolean)
  709.     Dim lNewMsg As Long, lNewOffSet As Long
  710.     Dim oBuf() As Byte, f As frmProgress
  711.     
  712.     Dim lMsg As Long, lOffset As Long
  713.     Dim frmJoin As frmJoinRequest
  714.     Dim dpPeer As DPN_PLAYER_INFO
  715.     Dim sFile As String, lUnique As Long
  716.     Dim oFile() As Byte, lFileSize As Long
  717.     
  718.     Dim lChunkSize As Long, oData() As Byte
  719.     
  720.     With dpnotify
  721.     GetDataFromBuffer .ReceivedData, lMsg, LenB(lMsg), lOffset
  722.     Select Case lMsg
  723.     Case MsgChat, MsgWhisper 'Make sure chat messages get to the chat window
  724.         If ChatWindow Is Nothing Then
  725.             Set ChatWindow = New frmChat
  726.         End If
  727.         ChatWindow.Show
  728.         Set moCallBack = ChatWindow
  729.     Case MsgSendDrawPixel, MsgClearWhiteBoard
  730.         If WhiteBoardWindow Is Nothing Then
  731.             Set WhiteBoardWindow = New frmWhiteBoard
  732.         End If
  733.         WhiteBoardWindow.Show
  734.         Set moCallBack = WhiteBoardWindow
  735.     Case MsgAskToJoin
  736.         If gfHost Then
  737.             'We are the host, pop up the 'Ask to join dialog
  738.             dpPeer = dpp.GetPeerInfo(dpnotify.idSender)
  739.             Set frmJoin = New frmJoinRequest
  740.             frmJoin.SetupRequest Me, dpnotify.idSender, dpPeer.Name
  741.             frmJoin.Show vbModeless
  742.         End If
  743.     Case MsgAcceptJoin
  744.         'We have been accepted
  745.         'Enumerate all the players and add anyone we don't already have listed
  746.         UpdatePlayerList
  747.         If Not (ChatWindow Is Nothing) Then ChatWindow.LoadAllPlayers
  748.         ConnectVoice Me
  749.     Case MsgRejectJoin
  750.         'We have been rejected
  751.         tmrJoin.Enabled = True
  752.         'We need to use a timer here, without it, we would be attempting to cleanup
  753.         'our dplay objects to restart our host before this message was done being processed.
  754.     Case MsgShowChat
  755.         'Someone wants to chat.  Open the chat window
  756.         If ChatWindow Is Nothing Then Set ChatWindow = New frmChat
  757.         ChatWindow.Show vbModeless
  758.         Set moCallBack = ChatWindow
  759.     Case MsgShowWhiteBoard
  760.         'Someone wants to draw.  Open the whiteboard window
  761.         If WhiteBoardWindow Is Nothing Then Set WhiteBoardWindow = New frmWhiteBoard
  762.         WhiteBoardWindow.Show vbModeless
  763.         Set moCallBack = WhiteBoardWindow
  764.     Case MsgSendFileRequest
  765.         'Someone wants to send us a file.  Should we accept?
  766.         dpPeer = dpp.GetPeerInfo(dpnotify.idSender)
  767.         GetDataFromBuffer .ReceivedData, lUnique, LenB(lUnique), lOffset
  768.         sFile = GetStringFromBuffer(.ReceivedData, lOffset)
  769.         LockReceiveCollection
  770.         Set f = New frmProgress
  771.         With f
  772.             .FileUniqueID = lUnique
  773.             .sFileName = sFile
  774.             .lDPlayID = dpnotify.idSender
  775.             Set .RequestForm = New frmTransferRequest
  776.             .RequestForm.SetupRequest Me, dpPeer.Name, .sFileName, .FileUniqueID, dpnotify.idSender
  777.             .RequestForm.Show vbModeless
  778.         End With
  779.         moReceivedFiles.Add f
  780.         UnlockReceiveCollection
  781.     Case MsgSendFileDeny
  782.         'We don't care about this file
  783.         GetDataFromBuffer .ReceivedData, lUnique, LenB(lUnique), lOffset
  784.         'Now remove this one
  785.         EraseSendFile lUnique
  786.     Case MsgSendFileAccept
  787.         'Ok, they do want us to send the file to them.. We will send it in chunks
  788.         'First we will send the file info
  789.         GetDataFromBuffer .ReceivedData, lUnique, LenB(lUnique), lOffset
  790.         'First we need to find the correct file in our send list
  791.         LockSendCollection
  792.         Set f = GetSendProgressForm(lUnique)
  793.         lNewOffSet = NewBuffer(oBuf)
  794.         lMsg = MsgSendFileInfo
  795.         AddDataToBuffer oBuf, lMsg, LenB(lMsg), lNewOffSet
  796.         With f
  797.             .lFileSize = FileLen(.sFileName)
  798.             AddDataToBuffer oBuf, .FileUniqueID, SIZE_LONG, lNewOffSet
  799.             AddDataToBuffer oBuf, .lFileSize, SIZE_LONG, lNewOffSet
  800.             dpp.SendTo .lDPlayID, oBuf, 0, DPNSEND_NOLOOPBACK Or DPNSEND_GUARANTEED
  801.             .SetFile .sFileName
  802.             .SetMax .lFileSize
  803.             .SetValue 0
  804.             .Show
  805.         End With
  806.         UnlockSendCollection
  807.     Case MsgSendFileInfo
  808.         'They just send us the file size, save it
  809.         GetDataFromBuffer .ReceivedData, lUnique, LenB(lUnique), lOffset
  810.         'First we need to find the correct file in our receive list
  811.         LockReceiveCollection
  812.         Set f = GetReceiveProgressForm(lUnique)
  813.         With f
  814.             GetDataFromBuffer dpnotify.ReceivedData, lFileSize, LenB(lFileSize), lOffset
  815.             .lFileSize = lFileSize
  816.             .SetFile .sFileName, True
  817.             .SetMax .lFileSize
  818.             .SetValue 0
  819.             .Show
  820.         End With
  821.         'Acknowledge that we received this part
  822.         lNewMsg = MsgAckFilePart
  823.         lNewOffSet = NewBuffer(oBuf)
  824.         AddDataToBuffer oBuf, lNewMsg, LenB(lNewMsg), lNewOffSet
  825.         AddDataToBuffer oBuf, lUnique, LenB(lUnique), lNewOffSet
  826.         dpp.SendTo dpnotify.idSender, oBuf, 0, DPNSEND_NOLOOPBACK Or DPNSEND_GUARANTEED
  827.         UnlockReceiveCollection
  828.     Case MsgSendFilePart
  829.         'They just send us the file size, save it
  830.         GetDataFromBuffer .ReceivedData, lUnique, LenB(lUnique), lOffset
  831.         GetDataFromBuffer .ReceivedData, lChunkSize, LenB(lChunkSize), lOffset
  832.         'First we need to find the correct file in our receive list
  833.         LockReceiveCollection
  834.         Set f = GetReceiveProgressForm(lUnique)
  835.         With f
  836.             ReDim oData(1 To lChunkSize)
  837.             'We just received a file part..  Append this to our current file
  838.             If .filNumber = 0 Then
  839.                 .filNumber = FreeFile
  840.                 If Dir$(App.Path & "\" & .sFileName) <> vbNullString Then Kill App.Path & "\" & .sFileName
  841.                 Open App.Path & "\" & .sFileName For Binary Access Write As #.filNumber
  842.             End If
  843.             GetDataFromBuffer dpnotify.ReceivedData, oData(1), lChunkSize, lOffset
  844.             Put #.filNumber, , oData
  845.             'Is this the end of the file?
  846.             .lCurrentPos = .lCurrentPos + lChunkSize
  847.             .SetValue .lCurrentPos
  848.             If .lCurrentPos >= .lFileSize Then
  849.                 'We're done with the file
  850.                 Close #.filNumber
  851.                 EraseReceiveFile .FileUniqueID
  852.             Else
  853.                 'Acknowledge that we received this part
  854.                 lNewMsg = MsgAckFilePart
  855.                 lNewOffSet = NewBuffer(oBuf)
  856.                 AddDataToBuffer oBuf, lNewMsg, LenB(lNewMsg), lNewOffSet
  857.                 AddDataToBuffer oBuf, lUnique, LenB(lUnique), lNewOffSet
  858.                 dpp.SendTo dpnotify.idSender, oBuf, 0, DPNSEND_NOLOOPBACK Or DPNSEND_GUARANTEED
  859.             End If
  860.         End With
  861.         UnlockReceiveCollection
  862.     Case MsgAckFilePart
  863.         GetDataFromBuffer .ReceivedData, lUnique, LenB(lUnique), lOffset
  864.         SendNextFilePart lUnique
  865.     Case MsgNewPlayerJoined
  866.         UpdatePlayerList 'Update our list here
  867.         If Not (ChatWindow Is Nothing) Then ChatWindow.LoadAllPlayers 'And in the chat window if we need to
  868.     End Select
  869.     End With
  870.     
  871.     If (Not moCallBack Is Nothing) Then moCallBack.Receive dpnotify, fRejectMsg
  872. End Sub
  873.  
  874. Private Sub DirectPlay8Event_SendComplete(dpnotify As DxVBLibA.DPNMSG_SEND_COMPLETE, fRejectMsg As Boolean)
  875.     'VB requires that we must implement *every* member of this interface
  876.     If (Not moCallBack Is Nothing) Then moCallBack.SendComplete dpnotify, fRejectMsg
  877. End Sub
  878.  
  879. Private Sub DirectPlay8Event_TerminateSession(dpnotify As DxVBLibA.DPNMSG_TERMINATE_SESSION, fRejectMsg As Boolean)
  880.     'VB requires that we must implement *every* member of this interface
  881.     If (Not moCallBack Is Nothing) Then moCallBack.TerminateSession dpnotify, fRejectMsg
  882.     mfTerminate = True
  883.     tmrUpdate.Enabled = True
  884. End Sub
  885.  
  886. Private Sub DirectPlayVoiceEvent8_ConnectResult(ByVal ResultCode As Long)
  887.     Dim lTargets(0) As Long
  888.     
  889.     lTargets(0) = DVID_ALLPLAYERS
  890.     On Error Resume Next
  891.     'Connect the client
  892.     dvClient.SetTransmitTargets lTargets, 0
  893.     If Err.Number <> 0 And Err.Number <> DVERR_PENDING Then
  894.         mlVoiceError = Err.Number
  895.         tmrVoice.Enabled = True
  896.         Exit Sub
  897.     End If
  898.  
  899. End Sub
  900.  
  901. Private Sub DirectPlayVoiceEvent8_CreateVoicePlayer(ByVal playerID As Long, ByVal flags As Long)
  902.     'VB requires that we must implement *every* member of this interface
  903. End Sub
  904.  
  905. Private Sub DirectPlayVoiceEvent8_DeleteVoicePlayer(ByVal playerID As Long)
  906.     'VB requires that we must implement *every* member of this interface
  907. End Sub
  908.  
  909. Private Sub DirectPlayVoiceEvent8_DisconnectResult(ByVal ResultCode As Long)
  910.     'VB requires that we must implement *every* member of this interface
  911. End Sub
  912.  
  913. Private Sub DirectPlayVoiceEvent8_HostMigrated(ByVal NewHostID As Long, ByVal NewServer As DxVBLibA.DirectPlayVoiceServer8)
  914.     'VB requires that we must implement *every* member of this interface
  915. End Sub
  916.  
  917. Private Sub DirectPlayVoiceEvent8_InputLevel(ByVal PeakLevel As Long, ByVal RecordVolume As Long)
  918.     'VB requires that we must implement *every* member of this interface
  919. End Sub
  920.  
  921. Private Sub DirectPlayVoiceEvent8_OutputLevel(ByVal PeakLevel As Long, ByVal OutputVolume As Long)
  922.     'VB requires that we must implement *every* member of this interface
  923. End Sub
  924.  
  925. Private Sub DirectPlayVoiceEvent8_PlayerOutputLevel(ByVal SourcePlayerID As Long, ByVal PeakLevel As Long)
  926.     'VB requires that we must implement *every* member of this interface
  927. End Sub
  928.  
  929. Private Sub DirectPlayVoiceEvent8_PlayerVoiceStart(ByVal SourcePlayerID As Long)
  930.     'VB requires that we must implement *every* member of this interface
  931. End Sub
  932.  
  933. Private Sub DirectPlayVoiceEvent8_PlayerVoiceStop(ByVal SourcePlayerID As Long)
  934.     'VB requires that we must implement *every* member of this interface
  935. End Sub
  936.  
  937. Private Sub DirectPlayVoiceEvent8_RecordStart(ByVal PeakVolume As Long)
  938.     'VB requires that we must implement *every* member of this interface
  939. End Sub
  940.  
  941. Private Sub DirectPlayVoiceEvent8_RecordStop(ByVal PeakVolume As Long)
  942.     'VB requires that we must implement *every* member of this interface
  943. End Sub
  944.  
  945. Private Sub DirectPlayVoiceEvent8_SessionLost(ByVal ResultCode As Long)
  946.     'VB requires that we must implement *every* member of this interface
  947. End Sub
  948.